
/*-----------------------------------------------*
Name: Haqdarshak Pilot Intervention-Analysis
Date Created: 30 July, 2018
Date Last Modified: 28 April, 2021
Created by: Aaron Berman and modified by Daniela Paz and Saumya Mathur on Nov.13/2020 
Uses Data: screen_amounts and pilot_intervention_assitance_followup
Creates Data: Latex Tables
Description: Creates tables for the main analysis on savings account application and scheme counts
*-------------------------------------------------*/




*..................................................
**Install user-written commands
foreach package in mdesc nmissing veracrypt {
     capture which `package'
	 if _rc==111 ssc install `package'
}
*..................................................
clear all
set more off
version 12.0
cap log close
pause off


//open log 
*cd "$logs"
*log using "cleaning_tables_5_6.smcl", replace



***Table 5
use "$intermediate_data/screen_amounts", clear

	********************************************************************

	*TABLE 5 UPDATED (SAVINGS ONLY)
	eststo clear 
	preserve
		keep if scheme_id == 2
		local normal_price "Rs. 100"

		forv i = 1/2 {
			local controls: word `i' of "" "screen_0 screen_50 screen_100"
			local screencontrol: word `i' of "NO" "YES"
			forv j = 1/2 {
				local outcome: word `j' of "atleast1_agreed_hh" "atleast1_applied_hh"

				eststo: reg `outcome' treat_100 treat_50 d_stratum_* `controls', robust 
				test treat_100=treat_50
				estadd scalar pval `r(p)'
				summ `outcome' if treat_0 == 1
				estadd scalar control_mean `r(mean)'
				estadd local screencontrol "`screencontrol'"
			}
		}

	//output to latex 
	cd "$Main"

	#delimit ;
	esttab *
		using "Table_6.tex", booktabs label se
		drop(_cons d_stratum_* screen_0 screen_50 screen_100)
		b(%12.3f)
		se(%12.3f)
		starlevels(* .10 ** .05 *** .01)
		mlabels("HH Member Agreed" "HH Member Completed Application" "HH Member Agreed" "HH Member Completed Application")
		varlab(treat_100 "Free Scheme" treat_50 "Half-Priced Scheme")
		scalars("control_mean Mean at Normal Price" "pval /(p/)-value (Free = Half-Priced)" "screencontrol Screening Price Controls")
		nonotes
		fragment
		r2
		replace;

	#delimit cr 
	
	
***Table 6

	use "$pilot/pilot_intervention_assitance_followup", clear
	
	 
	//label reasons for refusal
	#delimit ;
	label define reasons 
	0	"Assistance is Complete"
	1	"Will complete application independently"
	2	"Don't have time to complete application"
	3	"Already submitted scheme application"
	4	"Already receiving scheme"
	5	"Not enough savings to invest on a regular basis"
	6	"Ineligible (not covered on government list)"
	7	"Ineligible (receives other government pension)"
	8	"Ineligible (government employee)"
	9	"Issue in document(s)"
	10	"Not permitted by another household member"
	11	"No longer interested"
	12	"Already have a bank account"
	13	"Do not want to pay assistance fee"
	14  "Died or relative died"
	15  "No longer eligible"
	999	"Other";

	#delimit cr 
	label values code reasons

	//combine certain categories 
	replace code = 4 if code == 3
	replace code = 6 if code == 15
	replace code = 8 if code == 7
	replace code = 11 if code == 13

	//rename schemes for clarity 
	replace scheme_name = "SS Pension" if scheme_name == "Atal Pension"
	replace scheme_name = "Home-Building" if scheme_name == "Awas Yojana"
	replace scheme_name = "Female Child Account" if scheme_name == "Sukanya"
	replace scheme_name = "LPG Gas" if scheme_name == "Ujjwala Yojana"
	replace scheme_name = "Child Support" if scheme_name == "Palaanhar"

	//specify order of schemes 
	label define order  1 "Savings Account" 2 "SS Pension" 3 "Home-Building" 4 "Old Age" 5 "Female Child Account" 6 "Widow Pension" 7 "LPG Gas" 8 "Child Support"
	encode scheme_name, gen(c2) label(order)
	eststo clear
	//tab reasons overall
	estpost tab code c2


	//output table
	cd "$Main"
	#delimit ;
	esttab using "Table_10.tex",
		label booktabs
		nomtitle
		varlabels(`e(labels)')
		nonumbers 
		nonotes
		noobs
		nogaps
		fragment
		unstack
		replace;
	#delimit cr 

